﻿/*
    jquery.messages.js for the Dot Net Nuke Ajax Search Module Copyright (C) 2011  Jaime Alberto 
    Jaramillo Zapata. (@g4m30n, peleleman@msn.com, jjaramillo@paradigmasolutions.com). This javascript
    function defines a plugin that along with jquery will allow you to create modal messages according
    to the type of the message.
    
    The following options are available:
    
    - messageType: a string with the message type. available values are 'information', 'success', 'warning'
    and 'error'. Default value: 'information'
    - title: a string containing the title for the modal window. Default value: Here comes the title.
    - text: a string containing the message to be displayed on the modal window. Default value: 'This is the message Text'.
    - size: an integer with the modal window size. Default value: 500. 
    
    This program is free software: you can redistribute it and/or modify it under the terms of the 
    
    GNU General Public License as published by the Free Software Foundation, version 3 of the License.

    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
    without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    See the GNU General Public License for more details.

    You should have received a copy of the GNU General Public License  along with this program.  If not, 
    see http://www.gnu.org/licenses/.
*/
jQuery.fn.ShowMessage = function (options) {
    var defaults = {
        messageType: 'information',
        title: 'Here comes the title',
        text: 'This is the message Text',
        size: 500
    };
    var options = $.extend(defaults, options);
    var html;
    switch (options.messageType) {
        case 'success':
            html = '<div><div style="margin-top: 20px; padding: 0 .7em;" class="ui-state-highlight ui-corner-all">'
					+ '<p><span style="float: left; margin-right: .3em;" class="ui-icon ui-icon-circle-check"></span>'
					+ '<strong>Hooray </strong>' + options.text + '.</p>'
				    + '</div></div>';
            break;
        case 'information':
        default:
            html = '<div><div style="margin-top: 20px; padding: 0 .7em;" class="ui-state-highlight ui-corner-all">'
					+ '<p><span style="float: left; margin-right: .3em;" class="ui-icon ui-icon-info"></span>'
					+ '<strong>Hey! </strong>' + options.text + '.</p>'
				    + '</div></div>';
            break;
        case 'warning':
            html = '<div><div style="padding: 0 .7em;" class="ui-state-error ui-corner-all">'
				    + '<p><span style="float: left; margin-right: .3em;" class="ui-icon ui-icon-notice"></span> '
					+ '<strong>Hold it right there buddy: </strong>' + options.text + '.</p>'
				    + '</div></div>';
            break;
        case 'error':
            html = '<div><div style="padding: 0 .7em;" class="ui-state-error ui-corner-all">'
				    + '<p><span style="float: left; margin-right: .3em;" class="ui-icon ui-icon-alert"></span> '
					+ '<strong>Oops! </strong>' + options.text + '.</p>'
				    + '</div></div>';
            break;
    }
    $(html).dialog(
            {
                buttons: {
                    'Ok': function () {
                        $(this).dialog("close");
                        $(this).dialog("destroy");
                    }
                },
                modal: true,
                title: options.title,
                resizable: false,
                width: options.size
            }
        );
};